Micron Document
NexusPi Git Node


Displaying Raw • Download

lib/microReticulum/src/Cryptography/HMAC.h copilot/add-rtnode-configuration-options (9529fa8a) Text, 2.67 KB

Tff7b72#Tff7b72pragma once

Tff7b72#Tff7b72include T8b949e"../Bytes.h"

Tff7b72#Tff7b72include T8b949e<Hash.h>
Tff7b72#Tff7b72include T8b949e<SHA256.h>
Tff7b72#Tff7b72include T8b949e<SHA512.h>
Tff7b72#Tff7b72include T8b949e<stdexcept>
Tff7b72#Tff7b72include T8b949e<memory>
Tff7b72#Tff7b72include T8b949e<cassert>

Te6edf3namespace Te6edf3RNS Tb4b4b4{ Te6edf3namespace Te6edf3Cryptography Tb4b4b4{

Te6edf3class Te6edf3HMAC Tb4b4b4{

Te6edf3publicTff7b72:
Tff7b72enum Te6edf3Digest Tb4b4b4{
Te6edf3DIGEST_NONETb4b4b4,
Te6edf3DIGEST_SHA256Tb4b4b4,
Te6edf3DIGEST_SHA512Tb4b4b4,
Tb4b4b4}Tb4b4b4;

Te6edf3using Te6edf3Ptr Tff7b72= Te6edf3stdTff7b72:Tff7b72:Te6edf3shared_ptrTff7b72<Te6edf3HMACTff7b72>Tb4b4b4;

Te6edf3publicTff7b72:
T8b949e/*
Create a new HMAC object.
key: bytes or buffer, key for the keyed hash object.
msg: bytes or buffer, Initial input for the hash or None.
digest: The underlying hash algorithm to use
*/
Te6edf3HMACTb4b4b4(Tff7b72const Te6edf3BytesTff7b72& Te6edf3keyTb4b4b4, Tff7b72const Te6edf3BytesTff7b72& Te6edf3msg Tff7b72= Tb4b4b4{Te6edf3BytesTff7b72:Tff7b72:Te6edf3NONETb4b4b4}Tb4b4b4, Te6edf3Digest Te6edf3digest Tff7b72= Te6edf3DIGEST_SHA256Tb4b4b4) Tb4b4b4{

Tff7b72if Tb4b4b4(Te6edf3digest Tff7b72=Tff7b72= Te6edf3DIGEST_NONETb4b4b4) Tb4b4b4{
Te6edf3throw Te6edf3stdTff7b72:Tff7b72:Te6edf3invalid_argumentTb4b4b4(Ta5d6ff"Ta5d6ffCannot derive key from empty input materialTa5d6ff"Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tff7b72switch Tb4b4b4(Te6edf3digestTb4b4b4) Tb4b4b4{
Tff7b72case Tff7b72DIGEST_SHA256Tb4b4b4:
Te6edf3_hash Tff7b72= Te6edf3stdTff7b72:Tff7b72:Te6edf3unique_ptrTff7b72<Te6edf3HashTff7b72>Tb4b4b4(Te6edf3new Te6edf3SHA256Tb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4;
Tff7b72breakTb4b4b4;
Tff7b72case Tff7b72DIGEST_SHA512Tb4b4b4:
Te6edf3_hash Tff7b72= Te6edf3stdTff7b72:Tff7b72:Te6edf3unique_ptrTff7b72<Te6edf3HashTff7b72>Tb4b4b4(Te6edf3new Te6edf3SHA512Tb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4;
Tff7b72breakTb4b4b4;
Tff7b72defaultTff7b72:
Te6edf3throw Te6edf3stdTff7b72:Tff7b72:Te6edf3invalid_argumentTb4b4b4(Ta5d6ff"Ta5d6ffUnknown ior unsuppored digestTa5d6ff"Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Te6edf3_key Tff7b72= Te6edf3keyTb4b4b4;
Te6edf3_hashTff7b72-Tff7b72>Te6edf3resetHMACTb4b4b4(Te6edf3keyTb4b4b4.Te6edf3dataTb4b4b4(Tb4b4b4)Tb4b4b4, Te6edf3keyTb4b4b4.Te6edf3sizeTb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4;

Tff7b72if Tb4b4b4(Te6edf3msgTb4b4b4) Tb4b4b4{
Te6edf3updateTb4b4b4(Te6edf3msgTb4b4b4)Tb4b4b4;
Tb4b4b4}
Tb4b4b4}

T8b949e/*
Feed data from msg into this hashing object.
*/
Tffa657void Te6edf3updateTb4b4b4(Tff7b72const Te6edf3BytesTff7b72& Te6edf3msgTb4b4b4) Tb4b4b4{
Te6edf3assertTb4b4b4(Te6edf3_hashTb4b4b4)Tb4b4b4;
Te6edf3_hashTff7b72-Tff7b72>Te6edf3updateTb4b4b4(Te6edf3msgTb4b4b4.Te6edf3dataTb4b4b4(Tb4b4b4)Tb4b4b4, Te6edf3msgTb4b4b4.Te6edf3sizeTb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4;
Tb4b4b4}

T8b949e/*
Return the hash value of this hashing object.
This returns the hmac value as bytes. The object is
not altered in any way by this function; you can continue
updating the object after calling this function.
*/
Te6edf3Bytes Te6edf3digestTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3assertTb4b4b4(Te6edf3_hashTb4b4b4)Tb4b4b4;
Te6edf3Bytes Te6edf3resultTb4b4b4;
Te6edf3_hashTff7b72-Tff7b72>Te6edf3finalizeHMACTb4b4b4(Te6edf3_keyTb4b4b4.Te6edf3dataTb4b4b4(Tb4b4b4)Tb4b4b4, Te6edf3_keyTb4b4b4.Te6edf3sizeTb4b4b4(Tb4b4b4)Tb4b4b4, Te6edf3resultTb4b4b4.Te6edf3writableTb4b4b4(Te6edf3_hashTff7b72-Tff7b72>Te6edf3hashSizeTb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4, Te6edf3_hashTff7b72-Tff7b72>Te6edf3hashSizeTb4b4b4(Tb4b4b4)Tb4b4b4)Tb4b4b4;
Tff7b72return Te6edf3resultTb4b4b4;
Tb4b4b4}

T8b949e/*
Create a new hashing object and return it.
key: bytes or buffer, The starting key for the hash.
msg: bytes or buffer, Initial input for the hash, or None.
digest: The underlying hash algorithm to use.
You can now feed arbitrary bytes into the object using its update()
method, and can ask for the hash value at any time by calling its digest()
method.
*/
Tff7b72static Tff7b72inline Te6edf3Ptr Te6edf3generateTb4b4b4(Tff7b72const Te6edf3BytesTff7b72& Te6edf3keyTb4b4b4, Tff7b72const Te6edf3BytesTff7b72& Te6edf3msg Tff7b72= Tb4b4b4{Te6edf3BytesTff7b72:Tff7b72:Te6edf3NONETb4b4b4}Tb4b4b4, Te6edf3Digest Te6edf3digest Tff7b72= Te6edf3DIGEST_SHA256Tb4b4b4) Tb4b4b4{
Tff7b72return Te6edf3PtrTb4b4b4(Te6edf3new Te6edf3HMACTb4b4b4(Te6edf3keyTb4b4b4, Te6edf3msgTb4b4b4, Te6edf3digestTb4b4b4)Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Te6edf3privateTff7b72:
Te6edf3Bytes Te6edf3_keyTb4b4b4;
Te6edf3stdTff7b72:Tff7b72:Te6edf3unique_ptrTff7b72<Te6edf3HashTff7b72> Te6edf3_hashTb4b4b4;

Tb4b4b4}Tb4b4b4;

T8b949e/*
Fast inline implementation of HMAC.
key: bytes or buffer, The key for the keyed hash object.
msg: bytes or buffer, Input message.
digest: The underlying hash algorithm to use.
*/
Tff7b72inline Tff7b72const Te6edf3Bytes Td2a8ffdigestTb4b4b4(Tff7b72const Te6edf3BytesTff7b72& Te6edf3keyTb4b4b4, Tff7b72const Te6edf3BytesTff7b72& Te6edf3msgTb4b4b4, Te6edf3HMACTff7b72:Tff7b72:Te6edf3Digest Te6edf3digest Tff7b72= Te6edf3HMACTff7b72:Tff7b72:Te6edf3DIGEST_SHA256Tb4b4b4) Tb4b4b4{
Te6edf3HMAC Te6edf3hmacTb4b4b4(Te6edf3keyTb4b4b4, Te6edf3msgTb4b4b4, Te6edf3digestTb4b4b4)Tb4b4b4;
Te6edf3hmacTb4b4b4.Te6edf3updateTb4b4b4(Te6edf3msgTb4b4b4)Tb4b4b4;
Tff7b72return Te6edf3hmacTb4b4b4.Te6edf3digestTb4b4b4(Tb4b4b4)Tb4b4b4;
Tb4b4b4}

Tb4b4b4} Tb4b4b4}

Served by rngit 1.4.2 - Generated in 0.02s